package org.vison.wonfu.framework.test.admin.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Repository;
import org.vison.wonfu.framework.dao.AbstractDao;
import org.vison.wonfu.framework.test.admin.dao.entity.AdminPO;
import org.vison.wonfu.framework.test.admin.dao.mapper.AdminMapper;

import java.util.List;

@Repository
public class AdminDao extends AbstractDao<AdminMapper, AdminPO> {
    public AdminPO findOne(Integer id) {
        return mapper.selectById(id);
    }

    public List<AdminPO> findList() {
        LambdaQueryWrapper<AdminPO> query = new LambdaQueryWrapper<>();
        return mapper.selectList(query);
    }

    public AdminPO queryOneByUsername(String username) {
        LambdaQueryWrapper<AdminPO> query = new LambdaQueryWrapper<>();
        query.eq(AdminPO::getUsername, username);
        return mapper.selectOne(query);
    }

    public boolean insert(AdminPO admin) {
        return create(admin) > 0;
    }

    public boolean updateAdmin(AdminPO admin) {
        return update(admin) > 0;
    }
}
